#Example 1

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.3
library(gganimate)
## Warning: package 'gganimate' was built under R version 3.6.3
library(gapminder)
## Warning: package 'gapminder' was built under R version 3.6.3
# For each of 142 countries, the package provides values for life  expectancy, GDP per capita,
# and population, every five years, from 1952 to 2007.
head(gapminder)     
## # A tibble: 6 x 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.
# Static plot
p <- ggplot(
  gapminder, 
  aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)) +
  geom_point(show.legend = FALSE, alpha = 0.7) +
  scale_color_viridis_d() +facet_wrap(~continent)+
  scale_size(range = c(2, 12)) +
  scale_x_log10() +labs(x = "GDP per capita", y = "Life expectancy")
p

# transition
p+ transition_time(year) + ease_aes('linear')+
  labs(title = "Year: {frame_time}")

# Save animation
anim_save("gapminder_animation.gif")

Example 2

# HSGPA vs. Grad GPA Data
# Dummy data on High School GPA and University graduating student 
# overall GPA by Gender
library(ggplot2)
library(gganimate)
gpa <- read.csv("Gradgender.csv")
str(gpa)
## 'data.frame':    1798 obs. of  5 variables:
##  $ Year  : int  2016 2016 2016 2016 2016 2016 2016 2016 2016 2016 ...
##  $ HSGPA : num  3.18 3.8 3.53 3.78 3.6 3.5 2.85 3.37 3.5 2.84 ...
##  $ Gender: Factor w/ 2 levels "Female","Male": 1 1 1 1 1 1 1 1 1 1 ...
##  $ GPA   : num  3.62 3.37 3.08 3.97 3.45 3.24 2.99 3.29 3.35 3.25 ...
##  $ Grad  : int  1 1 1 1 1 1 1 1 1 1 ...
gpa<- na.omit(gpa)
# Static plot
p <- ggplot(
  gpa, 
  aes(x = HSGPA, y=GPA,colour = Gender))+ ggtitle("HSGPA VS. GPA by Gender")+
  geom_point()+scale_x_continuous(breaks = c(2016:2020))+  xlab(NULL) + ylab(NULL)+theme(legend.position="none")+
  theme(text = element_text(size = 15))+ facet_wrap(~Gender)
p

# Transition
p + transition_time(Year) + ease_aes('linear')+
  labs(title = "Year: {frame_time}")

# Save animation
anim_save("hsgpa_gpa_animation.gif")

Example 3

# Retention & Graduation Rates
# Ten year trend of University Retention and Graduation Rates
library(ggplot2)
library(gganimate)
library(directlabels)
## Warning: package 'directlabels' was built under R version 3.6.3
rg <- read.csv("RGanim2.csv")
str(rg)
## 'data.frame':    22 obs. of  3 variables:
##  $ Year    : int  2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 ...
##  $ variable: Factor w/ 2 levels "Graduation Rate",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ value   : int  68 68 66 66 70 71 73 75 73 72 ...
head(rg)
##   Year       variable value
## 1 2010 Retention Rate    68
## 2 2011 Retention Rate    68
## 3 2012 Retention Rate    66
## 4 2013 Retention Rate    66
## 5 2014 Retention Rate    70
## 6 2015 Retention Rate    71
# Static plot
g <-ggplot(rg,aes(x=Year, y=value,col=variable, group = variable)) +geom_line(size=1)+ geom_point()+
  xlab(NULL) + ylab(NULL) +  scale_color_manual(values=c("black","firebrick")) +ggtitle("Retention & Graduation Rate")+
  geom_dl(aes(label = variable), method = list(dl.trans(x = x + 0.2), "last.points", cex = 1.0)) +
  theme(legend.position="none")+ scale_x_continuous(breaks = c(2010:2020))+ theme(text = element_text(size = 15))
g

# Transition
g+  transition_reveal(Year) + ease_aes('cubic-in-out')

# Save animation
anim_save("retgradrates_animation.gif")